13. Output Devices

Let's beat the dinosaur

The idea for this exercise is to use a sensor that depending on the amount of light in the environment sends a signal and performs an action, which in our case will be to trigger a click and make the dinosaur jump to prevent it from dying.

In order to build this device we need :

Sensors - LDR

An LDR is a resistor that varies its electrical resistance value depending on the amount of light incident on it. It is also called a photoresistor or photoresistor. The electrical resistance value of an LDR is low when light is shining on it (in some cases it can drop to as low as 50 Ohms) and very high when it is dark (it can be 1 MOhm or more).

LDRs are made of a photosensitive semiconductor crystal such as cadmium sulfide (CdS). These cells are sensitive to a wide range of light frequencies, from infrared through visible light to ultraviolet. Photoresistors made from cadmium sulfide are extremely sensitive to the range of light radiations that are visible in the human spectrum. Photoresistors made from lead sulfide are particularly sensitive to infrared radiation. Translated with www.DeepL.com/Translator (free version)

Micro Servo 9g SG90

The SG90 servo has a universal "S" type connector that fits most radio control receivers. This type of servo is ideal as its power requirements are quite low and it is allowed to be powered from the same power supply as the control circuit. For example, if it is connected to an arduino board, it can be powered during testing from the USB port of the PC without much trouble.

Features

Speed: 0.10 sec/60° @ 4.8V
Torque: 1.8 Kg-cm @ 4.8V
Operating Voltage: 3.0-7.2V
Operating temperature: -30 ℃ ~ 60 ℃
Rotation angle: 180°.
Pulse width: 500-2400 µs
Connector cable length: 24.5cm

Protoboard

Breadboard, is a test board in which electronic elements and wires can be inserted to assemble circuits without the need to solder any of the components. Protoboards have holes connected to each other by means of small metal plates. Usually, these boards follow an arrangement in which holes in the same row are connected to each other and holes in different rows are not. The holes in the boards are usually 2.54 millimeters (0.1 inch) apart. A Protoboard is an instrument that allows testing of a circuit design without the need to solder or desolder components. Connections on a Protoboard are made by simply inserting the components, allowing circuits to be assembled and modified more quickly. Translated with www.DeepL.com/Translator (free version)

Arduino One

The Arduino Uno is an open source microcontroller board based on the ATmega328P microchip. The board is equipped with sets of digital and analog I/O pins that can be connected to various expansion boards and other circuits. The board has 14 digital pins, 6 analog pins and programmable with the Arduino IDE (Integrated Development Environment) via a USB type B cable.3 It can be powered by the USB cable or by an external 9-volt battery, although it accepts voltages between 7 and 20 volts. Translated with www.DeepL.com/Translator (free version)

Let's assemble

The LDR type sensor is connected to the Arduino board one through an analog pin and one digital pin also having a 10kOhm resistor. the idea is that when the sensors either of the two with function "O" has a lower analog signal As 60 which means a dark color that is when it passes the obstacles this send a signal and actuate the servomotor jumping the dinosaur.

The sensors are placed at a distance from the "dinosaur" and the servomotor is glued to the surface of the computer ensuring that when it moves, it presses the key needed to make the jump.

Several things are necessary to remove the code and calibrate the sensor:

The first is to keep in mind how much is the distance from the target to the sensor and based on that calculate the response time (trial error) and then place a parameter that reduces the response time as the map is made faster.

The second is to verify what are the levels that the sensor registers when it is in the dark tone of the obstacles and when it is with the white background.

The Code

The Result

Phone

(+57) 305-257 10 63