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
SRF10 Ultrasonic sensors SRF10 connector description This module used I2C as a protocol to communication with MCU. This module support to use with more than one module in system up to 16 module. We can set ID address for each module before integrated to the system, About how to change ID address click here . For distance to measure this module can measure from 6 cm to 6 m. Sample code: #include <Wire.h> //For Ultrasonic //ADDRESS #define Front_Left 112 #define Front_Right 114 #define CMD 0x00 #define Read_inch 0x50 #define Read_cen 0x51 #define Read_micro_sec 0x52 #define Read_pointer 0x02 void setup() { // put your setup code here, to run once: Serial.begin(115200); Wire.begin(); } void loop() { // put your main code here, to run repeatedly: //Correct Data Serial.println("----"); read_distance_ultrasonic(Front_Left); delay(75); read_distance_ultrasonic(Front_Right); delay(75); } int read_distance_ultrasonic(int addr){ i...
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...
Comments
Post a Comment