Sharp 2Y0A21 F 03 Distance Measuring Sensor Unit Sharp 2Y0A21 F 03 This sensor can measure a distance from 10 to 80 cm with analog output. The range of output voltage is defined as a graph below. Voltage output from 0.4 to 2.25 V (80 to 10 cm) Sample Code: void setup() { // put your setup code here, to run once: pinMode(A6, INPUT); pinMode(A7, INPUT); Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: Serial.println(analogRead(A6)); delay(1); Serial.println(analogRead(A7)); delay(1000); } Because the output of this sensor in analog output, So we can read data easily by using ADC. (analogRead() function in arduino) In this code, we read from 2 sharp sensors and print output to a serial port. Reference: Datasheet
CMPS03 Compass Module CMPS03 connector description This module used I2C as a protocol to communicate with MCU and use 5V for power supply. Data from I2C is compass Bearing as a word, i.e. 0-3599 for a full circle, representing 0-359.9 degrees. Sample Code: /* CMPS03 with arduino I2C example This will display a value of 0 - 359 for a full rotation of the compass. The SDA line is on analog pin 4 of the arduino and is connected to pin 3 of the CMPS03. The SCL line is on analog pin 5 of the arduino and is conected to pin 2 of the CMPS03. Both SDA and SCL are also connected to the +5v via a couple of 1k8 resistors. A switch to callibrate the CMPS03 can be connected between pin 6 of the CMPS03 and the ground. */ #include <wire .h> #define ADDRESS 0x60 //defines address of compass void setup(){ Wire.begin(); //conects I2C Serial.begin(9600); } void loop(){ byte highByte; byte lowByte; Wire.beginTransmission(ADDRESS); //starts communication
Change I2C Address of SRF10 Address Long Flash Short flashes Decimal Hex 224 E0 1 0 226 E2 1 1 228 E4 1 2 230 E6 1 3 232 E8 1 4 234 EA 1 5 236 EC 1 6 238 EE 1 7 240 F0 1 8 242 F2 1 9 244 F4 1 10 246 F6 1 11 248 F8 1 12 250 FA 1 13 252 FC 1 14 254 FE 1 15 Address Table For SRF10 can set ID for I2C up to 16 address as a table upper, So this post is about how to set ID for every SRF10. First, you need to have an only one SRF10 connect to I2C bus then use to the following code. Change Address Code: #include <Wire.h> #define ADDRESS byte(0x72) //defines address #define NEW_ADDRESS byte(0xEC) //defines address #define CMD byte(0x00) void setup() { // put your setup code here, to run once: Wire.begin(); //conects I2C Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: delay(5000); Serial.println("Begin"); Wire.beginTransmission(ADDRESS); Wire.write(CMD); Wire.write(byte(0xA0)); Wire.end
Comments
Post a Comment