Hardware RNG

From XinCheJian
Jump to navigation Jump to search

Connect an antenna to analog input 0 of any Arduino or Arduino variant.

Write in this code:

int sensorValue = 0;  // variable to store the value coming from the sensor
byte outputbyte = 0;
int counter = 0;

void setup() {
  pinMode(13, OUTPUT);  
  Serial.begin(57600);
  analogReference(DEFAULT);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(0);    
  // status LED
  if (bitRead(sensorValue, 0) == 0)
  {
      digitalWrite(13, LOW);
  }
  else
  {
      digitalWrite(13, HIGH);
  }
  delay(1);
  bitWrite(outputbyte, 2 * counter, bitRead(sensorValue, 0));
  bitWrite(outputbyte, 2 * counter + 1, bitRead(sensorValue, 1));
  counter++;
  if (counter == 4)
  {
      counter = 0;
      Serial.print(outputbyte, HEX);
  }
}