Analog kit modules on A0 to A3, on an Arduino Uno
A KY-035 Hall sensor, a TEMT6000 light sensor, a rotation sensor and a steam sensor on A0 to A3, printed twice a second. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $38. On Mokxi they're free.
What you'll learn
- Reading several analog sensors
- What a Hall sensor measures
- Analog sensors share power and ground
- Printing many values on one line
- Difficulty: Beginner
- Time: About 15 minutes
- Board: Arduino Uno R3
- Parts: 6
How it works
Four little analog sensor modules share one breadboard and all read with analogRead. A KY-035 Hall sensor goes to A0, a TEMT6000 light sensor to A1, a rotation sensor to A2, and a steam sensor to A3. All four share 5 V and ground.
The Hall sensor rests near 512 and moves up for a south pole and down for a north pole. The light sensor gives 5 mV per lux. The rotation sensor goes from 0 to 1023 as it turns, and the steam sensor rises as its comb gets wet.
Twice a second the sketch prints all four readings on one line: hall, light, knob and steam.
Parts list
6 parts, plus the jumper wires. They retail for about $38; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Full-size breadboard
- 1 × Analog Hall sensor, KY-035
- 1 × Ambient light sensor, TEMT6000
- 1 × Analog rotation sensor
- 1 × Steam sensor
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Analog Hall sensor, KY-035 pin GND | Arduino Uno R3 pin GND |
| Ambient light sensor, TEMT6000 pin GND | Arduino Uno R3 pin GND |
| Analog rotation sensor pin GND | Arduino Uno R3 pin GND |
| Steam sensor pin GND | Arduino Uno R3 pin GND |
| Analog Hall sensor, KY-035 pin VCC | Arduino Uno R3 pin 5V |
| Ambient light sensor, TEMT6000 pin VCC | Arduino Uno R3 pin 5V |
| Analog rotation sensor pin VCC | Arduino Uno R3 pin 5V |
| Steam sensor pin VCC | Arduino Uno R3 pin 5V |
| Analog Hall sensor, KY-035 pin S | Arduino Uno R3 pin A0 |
| Ambient light sensor, TEMT6000 pin SIG | Arduino Uno R3 pin A1 |
| Analog rotation sensor pin S | Arduino Uno R3 pin A2 |
| Steam sensor pin S | Arduino Uno R3 pin A3 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Four analog kit modules on A0 to A3.
//
// KY-035 Hall S -> A0 TEMT6000 SIG -> A1
// rotation S -> A2 steam S -> A3
// every + (VCC) -> 5V every - (GND) -> GND
//
// The Hall sensor rests at half the supply, about 512, and moves up for a
// south pole and down for a north. The TEMT6000 gives 5 mV a lux. The
// rotation sensor runs 0 to 1023 as it turns, and the steam sensor rises as
// its comb fogs.
//
// Drag the magnet, the light, the knob and the steam.
void setup() {
Serial.begin(9600);
Serial.println("Mokxi Uno: Hall, light, rotation and steam on A0 to A3");
}
void loop() {
Serial.print("hall ");
Serial.print(analogRead(A0));
Serial.print(" light ");
Serial.print(analogRead(A1));
Serial.print(" knob ");
Serial.print(analogRead(A2));
Serial.print(" steam ");
Serial.println(analogRead(A3));
delay(500);
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Starts the serial port at 9600 and prints a line that names the four modules and pins.
void setup() {
Serial.begin(9600);
Serial.println("Mokxi Uno: Hall, light, rotation and steam on A0 to A3");
}loop sketch.ino
Reads A0 to A3 with analogRead, printing each with a label on a single line, then waits 500 ms.
void loop() {
Serial.print("hall ");
Serial.print(analogRead(A0));
Serial.print(" light ");
Serial.print(analogRead(A1));
Serial.print(" knob ");
Serial.print(analogRead(A2));
Serial.print(" steam ");
Serial.println(analogRead(A3));
delay(500);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- A reading is stuck at 0 or 1023 This project
Check the module has 5 V and ground, and its signal pin goes to the right analog pin. - The readings look mixed up This project
Hall is A0, light is A1, rotation is A2, steam is A3. - The reading is about half the supply with no magnet and the changes are small. A 49E gives only a few mV per gauss. Analog Hall sensor
Read the idle level at startup and watch the change from it. Average several analog readings. Bring the magnet close, and note that a south pole raises the value. - Poles seem reversed or the output is noisy. The sensor has a polarity and picks up supply noise. Analog Hall sensor
Flip the magnet if the sign is the wrong way. Power the module from a clean 5 V or 3.3 V, and scale for your ADC. Join the grounds. - The light reading is always near zero or always maxed out. Ambient light sensor
Check the signal wire goes to an analog input and the board is powered from the same voltage as your ADC reference. Do not point it at a strong light source. - Readings do not match a lux meter. Ambient light sensor
The signal is a voltage that rises with light. Convert counts to volts, then volts to lux using the sensor's sensitivity. Treat the result as an estimate. - analogRead stays at zero or jumps randomly. Analog rotation sensor
Connect + to the supply, - to ground and S to an analog pin. S is the wiper. A floating S pin gives random values. Share the ground with the Arduino. - Turning it the right way gives backward numbers. Analog rotation sensor
Swap the + and - wires, or reverse the value in code with 1023 minus the reading. Small jitter is normal, so average a few samples.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.