Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Shock sensor
Software & Tools
Arduino IDE
Project description
Code
Shock_Sensor_SW18010P_WellTronic
c_cpp
1//**********************************************************************************************************// 2// Author: 3// WellTronic 4// 5// Description: 6// This code is part of a video series covering all Arduino sensors from the Arduino sensor kit. 7// One of the sensors in this video series is the SW18010P shock sensor. 8// 9// In this video I will explain step by step how to use the SW18010P shock sensor 10// https://www.youtube.com/watch?v=hDqkDn6dVJ4&t=177s 11// 12// You're also welcome to take a look at the YouTube channel for more details about hardware and software. 13// https://www.youtube.com/channel/UC0UCNqE8i4unG8nfuakd0vw 14// 15// Enjoy working with this sensor and see you soon :) ! 16// 17//**********************************************************************************************************// 18 19 20int shockSensorPin = 2; 21int greenLedPin = 3; 22int redLedPin = 4; 23 24bool shockSensorSate = 0; 25 26void setup() { 27pinMode(shockSensorPin,INPUT); 28pinMode(greenLedPin,OUTPUT); 29pinMode(redLedPin,OUTPUT); 30 31shockSensorSate = digitalRead(shockSensorPin); 32} 33 34void loop() { 35 36 if (shockSensorSate == 1){ 37 digitalWrite(greenLedPin,LOW); 38 for ( int i=0; i < 10;i++){ 39 digitalWrite(redLedPin,HIGH); 40 delay(150); 41 digitalWrite(redLedPin,LOW); 42 delay(150); 43 if ( i == 9){ 44 shockSensorSate = 0; 45 } 46 } 47 } 48 else { 49 shockSensorSate = digitalRead(shockSensorPin); 50 digitalWrite(greenLedPin,HIGH); 51 } 52 53 54 55 56} 57
Comments
Only logged in users can leave comments