Micropython Lesson 7
Turn a physical parameter to an analog electric current
In this example, you are learning how to use a proximity sensor. This sensor (TCRT5000) uses reflection as a surface theory to work. A white and polished surface reflects a large percentage of light and a black and rough surface absorbs (not reflect) a large percentage of light that incidence on the surface.
- Reflection theory using Infrared radiations.
- Turning physical parameters to an analog electric signal.
A proximity sensor is a sensor able to detect the presence of nearby objects without any physical contact. A proximity sensor often emits an electromagnetic field or a beam of electromagnetic radiation (infrared, for instance), and looks for changes in the field or return signal.
- Supply voltage 3.3V ~ 5V
- Detect distance 1 mm ~ 8 mm
- As the first step, you should connect a Magicbit proximity sensor to the Magicbit core board. For this, you can use one side connector from four-side connectors of the Magicbit core board or if you want to extend the length of the connection you can use jumper wires.
- For this example, the proximity sensor was connected to the upper left connector of the Magicbit core board.
- Then connect the Magicbit to your pc and upload the code. You can get outputs using a serial monitor.
from machine import Pin, ADC from time import sleep prox = ADC(Pin(34)) prox.atten(ADC.ATTN_11DB) #Full range: 3.3v while True: prox_value = prox.read() print(prox_value) sleep(0.1)