Materials:
* Arduino board
* 1-Wire iButton (Dallas DS1990A or similar)
* 4.7kΩ pull-up resistor
* Breadboard and jumper wires
Circuit Diagram:
«`
GND ———|| |——— GND
VCC ———|| |——— IButton Data
Arduino Pin ———|| |——— Pull-up Resistor
«`
Code:
«`
#include
#define IBUTTON_PIN A0 // Specify the Arduino pin connected to the iButton
OneWire ds(IBUTTON_PIN); // Create a OneWire object for communication with the iButton
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
ds.reset(); // Reset the 1-Wire bus
// Send the «Read ROM» command to the iButton
ds.write(0x33);
// Read the 8-byte ROM code from the iButton
byte rom[8];
for (int i = 0; i < 8; i++) {
rom[i] = ds.read(); // Read each byte of the ROM code
}
// Print the ROM code in hexadecimal format
Serial.print("ROM Code: ");
for (int i = 0; i < 8; i++) {
Serial.print(rom[i], HEX); // Print each byte as a 2-digit hexadecimal number
}
Serial.println(); // Newline for clarity
delay(1000); // Delay for 1 second
}
```
Explanation:
* The `OneWire` library is used to communicate with the iButton over the 1-Wire bus.
* The `reset()` function initializes the 1-Wire bus and ensures the iButton is ready to receive commands.
* The `write()` function sends a command to the iButton. The "Read ROM" command (0x33) is used to retrieve the iButton's unique 8-byte ROM code.
* The `read()` function reads bytes from the iButton. The ROM code is stored in an array of 8 bytes.
* The ROM code is printed in hexadecimal format to the serial console for easy identification and debugging.