Showing posts with label MOSFET. Show all posts
Showing posts with label MOSFET. Show all posts

Wednesday, September 14, 2022

How to Control Water Flow with Arduino IoT Cloud and a Solenoid Parts 1 and 2

In this two part series we look at how to control a Solenoid using an ESP32 board and the Arduino IoT Cloud. In part one we focus on what a solenoid is and the hardware needed to drive a solenoid open or closed. In part 2 we focus on setting up the Arduino IoT Cloud control.

\



Link to tutorial on setting up device on Arduino IoT Cloud: https://docs.arduino.cc/arduino-cloud/getting-started/esp-32-cloud


//**************Arduino Code from Tutorial*********************
#include "thingProperties.h"

#define SOLENOID_PIN 21

void setup() {
  pinMode(SOLENOID_PIN,OUTPUT);
  digitalWrite(SOLENOID_PIN,LOW);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  
  if(water_Scheduler.isActive() || solenoidState) {
    digitalWrite(SOLENOID_PIN, HIGH);
  }
  else {
    digitalWrite(SOLENOID_PIN, LOW);
  } 
}



/*
  Since SolenoidState is READ_WRITE variable, onSolenoidStateChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onSolenoidStateChange()  {
  // Add your code here to act upon SolenoidState change
  /*
  if (solenoidState) {
    digitalWrite(SOLENOID_PIN, HIGH);
  }
  else {
    digitalWrite(SOLENOID_PIN, LOW);
  } 
  */
}

/*
  Since WaterScheduler is READ_WRITE variable, onWaterSchedulerChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onWaterSchedulerChange()  {
  // Add your code here to act upon WaterScheduler change
}

Monday, December 9, 2019

Designing an Automatic Battery Cutoff Circuit to Prevent Over Discharge of Rechargeable Batteries Part 2

In this video we will design an automatic battery cutoff circuit to prevent damaging over discharge of rechargeable batteries. In part 2 we test the design and discuss MOSFET and Voltage Detector specs.




BOM of battery cutoff circuit: 
  • S-1011A70-M6T1U4 Voltage Detector from ABLIC
  • DMP4015SSS-13 P Chan MOSFET from Diodes Inc
  • BSS138 N Chan MOSFET from multiple manufacturers
  • RSX051VYM30FHTR Schottky Diode from ROHM Semi
  • 2x 3.3 nF Ceramic Capacitor
  • ~100 kOhm Resistor
  • 1 to 10 MOhm Resistor (used 4.7M in example circuit)

PCB Layout of Battery Cutoff Circuit

Wednesday, December 27, 2017

Designing a Driver Circuit for a Bipolar Stepper Motor Part 1

In this video we design a low cost driver circuit for a four wire bipolar stepper motor using two H bridges.




//********************Arduino code from video***********************
#include <Stepper.h>

const int numberOfSteps = 100;  //number of steps you want your stepper motor to take

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(numberOfSteps, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
}

void loop() {
  myStepper.step(numberOfSteps);
  delay(1000);
}

Wednesday, October 11, 2017

How to Build a Simple DC Electronic Load with Arduino Part 1

In this video we look at how to make a simple DC electronic load with Arduino and some simple components.





//****************Arduino code from video************
/*
 * This code was used for a tutorial on how to build a simple eload with Arduino
 * The Tutorial can be found on the ForceTronics YouTube Channel
 * This code is public domain and free for anybody to use at their own risk
 */
void setup() {
  pinMode(A0, OUTPUT); //A0 DAC pin to output
  analogWriteResolution(10); //default DAC resolution is 8 bit, swith it to 10 bit (max)
}

void loop() {
  //create pulsed current profile
  analogWrite(A0, 16); //Set DAC to approximately 10mV --> current 10mV / 5ohm = 2 mA
  delay(500);
  analogWrite(A0,310); //Set DAC to 1V --> current 1V / 5ohm = 200 mA
  delay(50);

}

Sunday, January 25, 2015

How to Use a MOSFET as a Switch

In this video we will cover:
  • What is a MOSFET
  • MOSFET switch vs mechanical switch
  • How to use MOSFET as a switch
  • Go over example using a MOSFET as a switch with Arduino



Arduino Code********************************************************************
//This example code was used on the Forcetronics YouTube Channel to demonstrate how to use 
//A MOSFET as a switch. The code is open for anybody to use or modify

const int nMOS = 2; //create variable for n channel MOSFET pin
const int pMOS = 3; //create variable for p channel MOSFET pin

void setup() {
  pinMode(nMOS, OUTPUT);   // set pin to output
  pinMode(pMOS, OUTPUT);   // set pin to output
}

void loop() {
  digitalWrite(nMOS, HIGH);   // set n MOSFET gate to high, this will turn it on or close switch
  digitalWrite(pMOS, HIGH);   // set p MOSFET gate to high, this will turn it off or open switch
  delay(750);
  digitalWrite(nMOS, LOW);    // set n MOSFET gate to low, this will turn it off or open switch
  digitalWrite(pMOS, LOW);    // set p MOSFET gate to low, this will turn it on or close switch
  delay(750);
}