Skip to content

12. Output devices

I designed a board with a solenoid (output) and a distance sensor (input).

Components

  • Schottky diode MINI-SMA
  • 1X04SMD (pin head for HC-SR04)
  • ATTINY44 SOIC14
  • 0 Ohm Resistor (2)
  • 10k Resistor
  • 1k Resistor
  • 499k Resistor
  • 5V Regulator SOT23
  • LED
  • 1x2 Pin-header
  • 1x6 Pin-header
  • 2x2 Pin-header
  • AVRISP
  • N Mosfet SOT23

The HC-SR04 is an ultrasonic sensor that uses sonar to determine distance to an object like bats or dolphins do. It is also known as an ultrasonic transducer based on the transmitter and receiver and mainly used to determine the distance from the target object. It emits an ultrasound at 40 000 Hz which travels through the air and if there is an object or obstacle on its path It will bounce back to the module. I was pleased with its non-contact range detection. Additionally, the amount of time it takes to send and receive waves can be used to determine how far the object is placed from the sensor. HC-SR04 Data Sheet The trig pin plays a vital role to initialize measurement for sending ultrasonic waves. It should be kept high for 10us for triggering the measurement, whereas, the echo pin remains high for short period based on the time taken by the ultrasonic waves to bounce back to the receiving end. source

Solenoids are similar to electromagnets: they are made of a big coil of copper wire with an armature (a slug of metal) in the middle. When the coil is energized, the slug is pulled into the center of the coil. This makes the solenoid able to pull (from one end) or push (from the other). This solenoid in particular is strong, when activated with up to 12VDC, the solenoid moves and then the voltage is removed it springs (return spring) back to the original position. To drive this solenoid I needed to add a diode and a mosfet into my design. To control the “turn on and off” process using a digital circuit I needed a switching device, I used an Nmosfet.

adafruit- solenoid

Next I compiled a program that executes the solenoid to fire when the distance sensor is triggered.

 #include <SoftwareSerial.h>
  const int trigPin = 9;
  const int echoPin = 8;
  const int RX = 1;
  const int TX = 0;
  const int solenoidPin = 3;    
  const int trigger = 10;
SoftwareSerial Serial (TX, RX);
  float distance, duration;

void setup () {
  pinMode (trigPin, OUTPUT);
  pinMode (echoPin, INPUT);
  Serial.begin (9600);
  pinMode(solenoidPin, OUTPUT);           //Sets the pin as an output
  //Serial.println ("Initializing");
}

void loop() {
  digitalWrite(trigPin, LOW);   
  delayMicroseconds(5);         
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);       
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;
  delay(10); // for data to be read correctly by processing.

  if (distance < trigger) {

  digitalWrite(solenoidPin, HIGH);    //Switch Solenoid ON
  delay(10);                      //Wait 1 Second
  digitalWrite(solenoidPin, LOW);     //Switch Solenoid OFF
  delay(10);

}
  }

See week 17 and week 20 for more examples of boards I designed and programmed with an output device.

Design Files

solenoid_hc-sr04_traces

solenoid_hc-sr04_interior

solenoid_hc-sr04_schematic

solenoid_hc-sr04_board


class index